local IndexController = {}

local db = require 'models.db'
local user = require 'library.user'
local helper = require 'library.helpers'

function IndexController:index()
    if not user:is_login() then
        self:redirect(helper:url('admin/index/login'))
    end

    self:redirect(helper:url('admin/articles/index'))
end

function IndexController:login()
    local p = {}

    return self:display(p)
end

function IndexController:logout()
   user:logout()
   self:redirect(helper:url('admin/index/login')) 
end

function IndexController:login_check()
    local p = {}
    local post=self:getRequest():POST()


    local ret=user:check(post['name'],post['password'],post['remember']);
    if ret==0 then
        self:redirect(helper:url('admin/index/index'))
    end

    local errort={[1]="用户名错误",[2]="密码错误"}

    p['code']=ret
    p['error']=errort[ret]

    return self:display('admin.index/login.html',p)

end

return IndexController
